package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.user.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haust.su.ghyy.common.result.Result;
import com.haust.su.ghyy.model.user.UserInfo;
import com.haust.su.ghyy.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author haustsusu
 * @create 2023-05-07-19:37
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    //用户的列表接口(条件查询带分页)
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable long page,
                       @PathVariable long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam=new Page<UserInfo>(page,limit);
        IPage<UserInfo> PageModel=
                userInfoService.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(PageModel);
    }


    //用户锁定功能,通过改变status的值完成锁定
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable long userId,
                       @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }


    //后台查看用户详情功能
    @GetMapping("show/{userId}")
    public Result show(@PathVariable long userId){
        //在后台显示用户详情功能
        Map<String,Object> map=userInfoService.show(userId);
        return Result.ok(map);

    }


    //用户认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
